﻿using System;
using YJKStairs.DataInfos;

namespace YJKStairs.Kit
{
	public static class EscalatorTurnManger
	{
		public static bool IsLeftRunNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				if (upStairsType == UpStairsType.UST_Right && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 3:
				if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if ((upStairsType == UpStairsType.UST_Mid || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsMidOneRunNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				if (upStairsType == UpStairsType.UST_Left && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 3:
				if ((upStairsType == UpStairsType.UST_Left || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if (upStairsType == UpStairsType.UST_Left && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsMidTwoRunNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				result = false;
				break;
			case 3:
				if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if (upStairsType == UpStairsType.UST_Right && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsRightRunNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				result = false;
				break;
			case 3:
				result = false;
				break;
			case 4:
				if ((upStairsType == UpStairsType.UST_Mid || upStairsType == UpStairsType.UST_Left) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsLeftRunNeedTurn3D(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType, bool bLRTurn, bool bTPTurn)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				if (bLRTurn && !bTPTurn)
				{
					UpStairsType upStairsType2 = UpStairsType.UST_Right;
					if (bLRTurn)
					{
						upStairsType2 = UpStairsType.UST_Left;
					}
					if (upStairsType == upStairsType2 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType3 = UpStairsType.UST_Right;
					if (upStairsType == upStairsType3 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType4 = UpStairsType.UST_Left;
					if (upStairsType == upStairsType4 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else
				{
					UpStairsType upStairsType5 = UpStairsType.UST_Right;
					if (upStairsType == upStairsType5 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				break;
			case 3:
				if (bLRTurn && !bTPTurn)
				{
					UpStairsType upStairsType6 = UpStairsType.UST_Mid;
					if (upStairsType == upStairsType6 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType7 = UpStairsType.UST_Mid;
					if (upStairsType == upStairsType7 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType8 = UpStairsType.UST_Mid;
					if (upStairsType == upStairsType8 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else
				{
					UpStairsType upStairsType9 = UpStairsType.UST_Mid;
					if (upStairsType == upStairsType9 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				break;
			case 4:
				if (bLRTurn && !bTPTurn)
				{
					UpStairsType upStairsType10 = UpStairsType.UST_Right;
					if (bLRTurn)
					{
						upStairsType10 = UpStairsType.UST_Left;
					}
					if ((upStairsType == UpStairsType.UST_Mid || upStairsType == upStairsType10) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType11 = UpStairsType.UST_Right;
					if ((upStairsType == UpStairsType.UST_Mid || upStairsType == upStairsType11) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType12 = UpStairsType.UST_Left;
					if ((upStairsType == UpStairsType.UST_Mid || upStairsType == upStairsType12) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else
				{
					UpStairsType upStairsType13 = UpStairsType.UST_Right;
					if ((upStairsType == UpStairsType.UST_Mid || upStairsType == upStairsType13) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				break;
			}
			return result;
		}

		public static bool IsMidOneRunNeedTurn3D(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType, bool bLRTurn, bool bTPTurn)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				if (bLRTurn && !bTPTurn)
				{
					UpStairsType upStairsType2 = UpStairsType.UST_Left;
					if (bLRTurn)
					{
						upStairsType2 = UpStairsType.UST_Right;
					}
					if (upStairsType == upStairsType2 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType3 = UpStairsType.UST_Left;
					if (upStairsType == upStairsType3 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType4 = UpStairsType.UST_Right;
					if (upStairsType == upStairsType4 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else
				{
					UpStairsType upStairsType5 = UpStairsType.UST_Left;
					if (upStairsType == upStairsType5 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				break;
			case 3:
				if (bLRTurn && !bTPTurn)
				{
					if ((upStairsType == UpStairsType.UST_Left || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if ((upStairsType == UpStairsType.UST_Left || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if ((upStairsType == UpStairsType.UST_Left || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if ((upStairsType == UpStairsType.UST_Left || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if (bLRTurn && !bTPTurn)
				{
					UpStairsType upStairsType6 = UpStairsType.UST_Left;
					if (bLRTurn)
					{
						upStairsType6 = UpStairsType.UST_Right;
					}
					if (upStairsType == upStairsType6 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType7 = UpStairsType.UST_Left;
					if (upStairsType == upStairsType7 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					UpStairsType upStairsType8 = UpStairsType.UST_Right;
					if (upStairsType == upStairsType8 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else
				{
					UpStairsType upStairsType9 = UpStairsType.UST_Left;
					if (upStairsType == upStairsType9 && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				break;
			}
			return result;
		}

		public static bool IsMidTwoRunNeedTurn3D(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType, bool bLRTurn, bool bTPTurn)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				result = false;
				break;
			case 3:
				if (bLRTurn && !bTPTurn)
				{
					if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if (bLRTurn && !bTPTurn)
				{
					if (upStairsType == UpStairsType.UST_Right && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if (upStairsType == UpStairsType.UST_Right && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if (upStairsType == UpStairsType.UST_Left && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (upStairsType == UpStairsType.UST_Right && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsRightRunNeedTurn3D(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType, bool bLRTurn, bool bTPTurn)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				result = false;
				break;
			case 3:
				result = false;
				break;
			case 4:
				if (bLRTurn && !bTPTurn)
				{
					UpStairsType upStairsType2 = UpStairsType.UST_Left;
					if (bLRTurn)
					{
						upStairsType2 = UpStairsType.UST_Right;
					}
					if ((upStairsType == UpStairsType.UST_Mid || upStairsType == upStairsType2) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = true;
					}
				}
				else if (!bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if ((upStairsType == UpStairsType.UST_Mid || upStairsType == UpStairsType.UST_Left) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if (bLRTurn && bTPTurn)
				{
					result = bTPTurn;
					if ((upStairsType == UpStairsType.UST_Mid || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
					{
						result = false;
					}
				}
				else if ((upStairsType == UpStairsType.UST_Mid || upStairsType == UpStairsType.UST_Left) && (placeType == Escalator.PlaceType.PT_CrossingSameDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsLeftRunDirectNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				if (upStairsType == UpStairsType.UST_Right && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 3:
				if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if ((upStairsType == UpStairsType.UST_Mid || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsMidOneRunDirectNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				if (upStairsType == UpStairsType.UST_Left && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 3:
				if ((upStairsType == UpStairsType.UST_Left || upStairsType == UpStairsType.UST_Right) && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if (upStairsType == UpStairsType.UST_Left && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsMidTwoRunDirectNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				result = false;
				break;
			case 3:
				if (upStairsType == UpStairsType.UST_Mid && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			case 4:
				if (upStairsType == UpStairsType.UST_Right && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}

		public static bool IsRightRunDirectNeedTurn(int nRunCount, UpStairsType upStairsType, Escalator.PlaceType placeType)
		{
			bool result = false;
			switch (nRunCount)
			{
			case 1:
				result = false;
				break;
			case 2:
				result = false;
				break;
			case 3:
				result = false;
				break;
			case 4:
				if ((upStairsType == UpStairsType.UST_Left || upStairsType == UpStairsType.UST_Mid) && (placeType == Escalator.PlaceType.PT_ParallelReverseDirect || placeType == Escalator.PlaceType.PT_CrossingReverseDirect))
				{
					result = true;
				}
				break;
			}
			return result;
		}
	}
}
